<template>
	<view>
		<view class="header">
			<u-navbar :border-bottom='false' back-icon-size='48' :background='background' back-icon-color='#FFFFFF'
				title="分销中心" title-color='#FFFFFF'></u-navbar>
			<view class="userInfo">
				<image class="headPic" :src="userInfo.head_pic" mode=""></image>
				<view class="infoBox">
					<view class="title">
						<text style="margin-right: 8rpx;">{{userInfo.nickname}}</text>
						<u-rate :disabled='true' :count="count" v-model="countNum" size='20' inactive-icon="star-fill"
							inactive-color='#048DD6' active-color='#FFE038' gutter='4' v-if="userInfo.user_level == 4">
						</u-rate>
					</view>
					<view class="extend">
						<view class="text">
							<text>推荐人ID：{{userInfo.recommend_user_id}} </text>
							<view class="icon" @click="showPop=true">
								<image style="width: 28rpx;height: 28rpx;margin-left: 20rpx;"
									src="../../../static/imgs/bang.png" mode=""></image>
							</view>
						</view>
					</view>
					<view class="lact">
						归属地：{{userInfo.province}}{{userInfo.city}}{{userInfo.district}}
					</view>
				</view>
			</view>
		</view>
		<view class="main">
			<view class="tixian">
				<view class="money">
					可提现佣金 <text class="rmb">¥</text><text class="price">{{commission.commission}}</text>
				</view>
				<view class="mon-btn" @click="navTo('./yjWithdraw')">
					提现
				</view>
			</view>
			<view class="cells">
				<u-cell-group :border='false'>
					<u-cell-item :border-top='false' title="我的佣金" :title-style="titleStyle"
						@click="navTo('./myReward/myReward')">
						<image class="icons" slot='icon' src="../../../static/imgs/wodeyj.png" mode=""></image>
					</u-cell-item>
					<u-cell-item :border-top='false' title="我的账单" :title-style="titleStyle"
						@click="navTo('./bill/bill')">
						<image class="icons" slot='icon' src="../../../static/imgs/yongjinmx.png" mode=""></image>
					</u-cell-item>
					<u-cell-item :border-top='false' title="我的推广" :title-style="titleStyle"
						@click="navTo('./promote/promote')">
						<image class="icons" slot='icon' src="../../../static/imgs/wodetg.png" mode=""></image>
					</u-cell-item>
					<u-cell-item title="我的海报" value="推广专属海报" :title-style="titleStyle" :value-style='valueStyle'
						@click="navTo('./poster/poster')">
						<image class="icons" slot='icon' src="../../../static/imgs/wodehb.png" mode=""></image>
					</u-cell-item>
				</u-cell-group>
			</view>
		</view>
		<u-popup v-model="showPop" mode="center" border-radius="16">
			<view class="popBox">
				<view class="title">
					请输入上级邀请码
				</view>
				<view class="inputBox">
					<input type="text" value="" placeholder="请输入上级邀请码" v-model="inviteCode" />
				</view>
				<view class="btn" @click="bangFn">
					提交
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import myRequest from '@/api/index.js'
	export default {
		data() {
			return {
				showPop: false,
				background: {
					backgroundColor: 'rgba(255,255,255,0)'
				},
				titleStyle: {
					'fontSize': '32rpx',
					'color': '#333333',
					'font-weight': '400'
				},
				valueStyle: {
					'fontSize': '28rpx',
					'color': '#999999',
				},
				count: 5,
				countNum: 0,
				userInfo: {},
				inviteCode: '',
				commission: {}
			}
		},
		onLoad() {
			this.getInfo()

		},
		onShow() {
			this.getData()
		},
		methods: {
			// 可提现佣金
			getData() {
				myRequest.mycommission().then(res => {
					this.commission = res.data
				})
			},
			// 绑定上级
			async bangFn() {
				let {
					inviteCode
				} = this
				let res = await myRequest.binduser({
					code: inviteCode
				})
				if (res.status) {
					uni.showToast({
						title: '绑定成功'
					})
				}
			},
			// 用户信息
			async getInfo() {
				let res = await myRequest.getUserInfo()
				if (res.status) {
					this.userInfo = res.data
					this.$store.commit('changeInfo', res.data) // 保存用户信息
				}
			},
			navTo(url) {
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style>
	page {
		background-color: #FFFFFF;
	}
</style>
<style lang="scss" scoped>
	.header {
		width: 100%;
		height: 410rpx;
		@include bgi('../../../static/imgs/minebgi.png');

		.userInfo {
			display: flex;
			align-items: center;
			padding-left: 28rpx;

			.headPic {
				width: 140rpx;
				height: 140rpx;
				border-radius: 50%;
			}

			.infoBox {
				margin-left: 16rpx;

				.title {
					font-size: 34rpx;
					font-family: Segoe UI;
					font-weight: 400;
					color: #FFFFFF;
				}

				.extend {
					display: flex;
					align-items: center;
					margin-top: 12rpx;

					.copy {
						margin-left: 16rpx;
						width: 28rpx;
						height: 28rpx;
					}

					.text {
						font-size: 28rpx;
						font-family: PingFang SC;
						font-weight: 400;
						color: #FFFFFF;
						display: flex;
						align-items: center;
					}
				}

				.lact {
					margin-top: 10rpx;
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #FFFFFF;
				}
			}
		}
	}

	.main {
		padding: 0 20rpx;
		margin-top: -70rpx;

		.tixian {
			width: 100%;
			height: 140rpx;
			background: #FFFFFF;
			box-shadow: 0px 6rpx 12rpx rgba(0, 0, 0, 0.05);
			border-radius: 24rpx;
			padding: 0 34rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.mon-btn {
				width: 160rpx;
				height: 68rpx;
				background: linear-gradient(180deg, #FCBD6A 0%, #FF8000 100%);
				border-radius: 40rpx;
				text-align: center;
				font-size: 32rpx;
				font-family: PingFang SC;
				font-weight: 400;
				line-height: 68rpx;
				color: #FFFFFF;
			}

			.money {
				font-size: 32rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #666666;
				display: flex;
				align-items: center;

				.rmb {
					margin-left: 20rpx;
					color: #FF7904;
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 400;
				}

				.price {
					margin-left: 4rpx;
					font-size: 44rpx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #FF7904;
				}
			}
		}

		.cells {
			margin-top: 40rpx;

			.icons {
				width: 56rpx;
				height: 56rpx;
				margin-right: 24rpx;
			}
		}
	}

	.popBox {
		width: 400rpx;
		padding: 20rpx 0;

		.title {
			width: 100%;
			height: 88rpx;
			text-align: center;
			line-height: 88rpx;
		}

		.inputBox {
			width: 360rpx;
			height: 88rpx;
			background-color: #F2F2F2;
			margin: 0 auto;

			input {
				width: 100%;
				height: 100%;
				font-size: 28rpx;
				text-indent: 10rpx;
			}
		}

		.btn {
			width: 200rpx;
			height: 66rpx;
			background-color: #3064FC;
			margin: 20rpx auto 0;
			border-radius: 16rpx;
			text-align: center;
			line-height: 66rpx;
			color: #FFFFFF;
		}
	}
</style>
